package com.oa.cc.action;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.oa.cc.service.EmpService;
import com.oa.cc.service.MessageService;
import com.oa.domain.Emp;
import com.oa.domain.Message;
import com.opensymphony.xwork2.ActionSupport;

public class EmpAction extends ActionSupport{
	private static final long serialVersionUID = 1L;
	
	private EmpService empService;
	private MessageService messageService;
	private List<Message> listMessage;
	private Integer mesCount;
	
	public void setMesCount(Integer mesCount) {
		this.mesCount = mesCount;
	}
	public Integer getMesCount() {
		return mesCount;
	}
	
	public void setListMessage(List<Message> listMessage) {
		this.listMessage = listMessage;
	}
	public List<Message> getListMessage() {
		return listMessage;
	}
	
	public void setMessageService(MessageService messageService) {
		this.messageService = messageService;
	}
	public MessageService getMessageService() {
		return messageService;
	}
	
	public void setEmpService(EmpService empService) {
		this.empService = empService;
	}
	private Emp emp;
	public void setEmp(Emp emp) {
		this.emp = emp;
	}
	public Emp getEmp() {
		return emp;
	}
	
	public String login(){
		List<Emp> list = empService.getEmpsByExample(emp);
		
		HttpSession session=ServletActionContext.getRequest().getSession();
		
		if(list.size()>0){
			Emp emp = list.get(0);
			listMessage = messageService.getMessagesByEmpno(emp.getEmpno());
			if(listMessage.size()>0){
				session.setAttribute("listMessage", listMessage);
			}
			session.setAttribute("emp", emp);
			return SUCCESS;
		}else{
			session.removeAttribute("emp");
			return ERROR;
		}
	}
}
